﻿// ----------------------------------------------------------------------------------
// <copyright file="HelperUtility.cs" company="Christopher Hines">
// Copyright (c) 2012 All Right Reserved
// </copyright>
// <author>Chris Hines</author>
// <date>2012-03-05</date>
// <summary>
//     A helper utility
// </summary>
// ----------------------------------------------------------------------------------

namespace Copperfield
{
    using System;

    /// <summary>
    /// A helper utility
    /// </summary>
    internal static class HelperUtility
    {
        /// <summary>
        /// Will determine if a Type derives from IComparable, and will throw an exception if not
        /// </summary>
        /// <param name="type">
        /// The type of object.
        /// </param>
        /// <param name="message">
        /// The exception message message.
        /// </param>
        public static void AssertIsIComparable(Type type, string message)
        {
            if (type != null && !typeof(IComparable).IsAssignableFrom(type))
            {
                throw new ArgumentException(message ?? string.Empty, "type");
            }
        }

        /// <summary>
        /// Will determine if a Type has a public paramaterless constructor, and will throw an exception if not
        /// </summary>
        /// <param name="type">
        /// The type of object.
        /// </param>
        /// <param name="message">
        /// The exception message message.
        /// </param>
        public static void AssertHasPublicParameterlessConstructor(Type type, string message)
        {
            if (type != null && type.GetConstructor(Type.EmptyTypes) == null)
            {
                throw new ArgumentException(message ?? string.Empty, "type");
            }
        }
    }
}
